#include "LOD.hpp"

LOD::LOD(const Camera& c, Asset* a, Vector<float> pos)
  : cam(c), root(a), assetPos(pos), lastDist(-1)
{
  ;
}

void LOD::calculate()
{
  const Vector<float> camPos(cam.position().x, cam.position().y, cam.position().z);
  int dist = assetPos.dist(camPos);
  if(dist >= LONG_DIST && lastDist != LONG_DIST)
  {
    root->changeQuality(LOW);
    lastDist = LONG_DIST;
  }
  else if(dist < LONG_DIST && dist >= MED_DIST && lastDist != MED_DIST)
  {
    root->changeQuality(MEDIUM);
    lastDist = MED_DIST;
  }
  else if(dist < MED_DIST && lastDist != SMALL_DIST )
  {
    root->changeQuality(HIGHT);
    lastDist = SMALL_DIST;
  }
}


/* Opti :

if HIGHT -> down 2 lvl
if MEDIUM ->down 1 lvl
LOW -> */